package com.lienlq.voicemusic.xmlprc;

import java.net.URI;

import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;
import org.xmlrpc.android.XMLRPCFault;

import android.os.Handler;
import android.util.Log;



public class XMLRPCMethod extends Thread {

	String method;
	 Object[] params;
	 Handler handler;
	 XMLRPCMethodCallback callback;
	 XMLRPCClient client;
	 URI uri;
	 
	 public  XMLRPCMethod(String method,XMLRPCMethodCallback callback)
		{
			this.method=method;
			this.callback=callback;
			this.handler=new Handler(); 
			uri=URI.create("http://183.91.14.229:8088"); 
			client=new XMLRPCClient(uri);
			
		}
	 public void call()
		{
			call(null);
		}
		public void call(Object[] params)
		{
			this.params=params;
			start();
		}
		@Override
		public void run() {
			// TODO Auto-generated method stub
			super.run();
			try{
				final Object result=client.callEx(method, params);
				handler.post(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						callback.CallFinished(result);
					}
				});
			}catch(final XMLRPCFault e)
			{
				Log.w(" XMLRPCFault", e.toString());
			}catch(final XMLRPCException e)
			{
				Log.w("XMLRPCException", e.toString());
			}
		}
		
	
}
